package com.sihuatech.coreagent.until;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.dom4j.Attribute;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class XmlParseUtil {
private static Map<String, String> map;
 
	
	public static String domjxml(String paramstr) throws Exception {
		
		String  tagContent  ="";
		try {
            // 将xml格式字符串转化为DOM对象
            org.dom4j.Document document = DocumentHelper.parseText(paramstr);
            document.getRootElement().asXML();
            // 获取根结点对象
            Element rootElement = document.getRootElement();
            // 循环根节点，获取其子节点
            for (Iterator iter = rootElement.elementIterator(); iter.hasNext();) {
                Element element = (Element) iter.next(); // 获取标签对象
             
                // 循环第一层节点，获取其子节点
                for (Iterator iterInner = element.elementIterator(); iterInner
                        .hasNext();) {
                    // 获取标签对象
                    Element elementOption = (Element) iterInner.next();
                    // 获取该标签对象的名称
                    String  tagName = elementOption.getName();  
                    if("BIPCode".equals(tagName)) {
                     tagContent = elementOption.getTextTrim();
                     break;
                    }
                   
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
		return tagContent;
	}
	
	public static void main(String[] args) {
		String xml ="<?xml version=\"1.0\" encoding=\"utf-8\"?><InterBOSS><Version>123</Version><TestFlag>123</TestFlag><BIPType><BIPCode>1234</BIPCode><ActivityCode>123</ActivityCode><ActionCode>123</ActionCode></BIPType><RoutingInfo><OrigDomain>123</OrigDomain><RouteType>123</RouteType><Routing><HomeDomain>123</HomeDomain><RouteValue>123</RouteValue></Routing></RoutingInfo><TransInfo><TransIDO>123</TransIDO><TransIDOTime>123</TransIDOTime></TransInfo></InterBOSS>";
		
		try {
			String domjxml = domjxml(xml);
			System.out.println(domjxml);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	}

}
